package cn.bopomo.dealer.base.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.bopomo.dealer.base.common.ServiceConfig;
import cn.bopomo.dealer.base.service.IOperatorService;
import cn.bopomo.dealer.base.util.ResultCode;
import cn.bopomo.dealer.base.vo.AuGroup;

public class GroupDeleteAction extends BaseAction {

	private String codeDescXMLPath = "/WEB-INF/code_description.xml";
	
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		response.setContentType("text/html;charset=UTF-8");
		response.setHeader("Cache-control","no-cache");
	
		StringBuffer result = new StringBuffer();
		
		if (!this.hasPermission(request)){
			result.append(ResultCode.OP_NO_PRIMITION).append("||").append("你没有该操作权限，请与管理员联系");
			response.getWriter().write(result.toString());
			return null;
		}
		
		IOperatorService os = (IOperatorService)this.findService(ServiceConfig.OPERATOR_SERVICE);
		String group_id = request.getParameter("gid");
		AuGroup group = os.getGroup(new Integer(group_id));
		
		if (group == null){
			result.append(ResultCode.OP_FAILED).append("||").append("没有该权限组的信息");
		}
		
		String check_result = os.deleteGroup(group);
		
		result.append(check_result).append("||").append(this.getCodeDescription(check_result,request.getSession().getServletContext().getResource(this.codeDescXMLPath).getPath()));
		response.getWriter().write(result.toString());
		return null;
	}
}
